<?php
declare(strict_types = 1);
namespace app\common\business;
use app\common\lib\sms\AliSms;
use app\common\lib\Num;
use app\common\lib\ClassArr;
class Sms
{
    public static function sendCode(string $phoneNumber,int $len, string $type = 'ali') :bool
    {
        //$code = Num::getCode($len);

        $code = 123456;
        //工厂模式
       // $type = ucfirst($type);
       // $class = "app\common\lib\sms\\".$type."Sms";
       // $sms = $class::sendCode($phoneNumber,$code);


        $classStats = ClassArr::smsClassStat();
        $classObj = ClassArr::initClass($type,$classStats,[],false);
        $sms = $classObj::sendCode($phoneNumber,$code);
        if($sms){
            cache(config("redis.code_pre").$phoneNumber,$code,config("redis.code_expire"));
        }
        return $sms;
    }
}